<template>
    <el-row>
      <el-col :span="12">
        <VueEcharts :option="option" style="width: 600px;height: 400px; margin: 0 auto;" > </VueEcharts>
      </el-col>
      <el-col :span="12">
        <VueEcharts :option="option1" style="width: 600px;height: 400px; margin: 0 auto;" > </VueEcharts>
      </el-col>
      <el-col :span="12">
        <VueEcharts :option="option2" style="width: 600px;height: 400px; margin: 0 auto;" > </VueEcharts>
      </el-col>
  
    </el-row>
    
   
  
  
  
  </template>
  <script setup lang="ts">
  import axios from 'axios';
  import { ref,reactive, onMounted } from 'vue';
  import 'echarts'
  import VueEcharts from 'vue-echarts'
  
  onMounted(()=>{
    LoadData()
  })
  
  //折线图
  const option=ref({});
  const option1=ref({});
  const option2=ref({});
  
  //加载数据
  const LoadData=()=>{
    axios.get("/api/Count/GetOrderCountList")
    .then(res=>{
      let OrderData=res.data.Data
  
      //依次获取日期和数量并保存到数组中
      let dataArray=OrderData.map((item:any)=>item.Day);
      let orderArray=OrderData.map((item:any)=>item.Count);
  
      //创建饼图所需数组
      let PieChart:any=[];
      //从后台返回的数据进行数据遍历,将数据保存到饼图数组中
      OrderData.forEach((element:any)=>{
        PieChart.push({value:element.Count,name:element.Day})
      });
  
      //折线图
      option.value = {
        xAxis: {
          type: 'category',
          data:dataArray
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: orderArray,
            type: 'line'
          }
        ]
      };
      //柱状图
      option1.value = {
        xAxis: {
          type: 'category',
          data:dataArray
        },
        yAxis: {
          type: 'value'
        },
        series: [
          {
            data: orderArray,
            type: 'bar'
          }
        ]
      };
      //饼图
      option2.value = {
          title: {
          text: '日订单统计',
          subtext: 'Fake Data',
          left: 'center'
        },
        tooltip: {
          trigger: 'item'
        },
        legend: {
          orient: 'vertical',
          left: 'left'
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: '50%',
            data: PieChart,
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0.5)'
              }
            }
          }
        ]
      };
  
  
  
  
  
    })
  }
  
  </script>